/***********************************************************************
 * Module:  Tag.java
 * Author:  Voja
 * Purpose: Defines the Class Tag
 ***********************************************************************/

package model.entity;

import static javax.persistence.GenerationType.IDENTITY;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

 @Entity
 @Table(name="tag")
public class Tag implements Serializable{

	private static final long serialVersionUID = 6862284545514762842L;

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "tag_id", unique = true, nullable = false)
	private Integer id;
	 
	@Column(name = "tag_text", unique = false, nullable = true)
	private String text;
	 
	@ManyToMany(fetch=FetchType.EAGER,mappedBy="tags")
	private Set<Photo> photos=new HashSet<Photo>();

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public Set<Photo> getPhotos() {
		return photos;
	}

	public void setPhotos(Set<Photo> photos) {
		this.photos = photos;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	@Override
	public String toString() {
		return "Tag [id=" + id + "]";
	}
	
	@Override
	public boolean equals(Object obj) {
		if(!(obj instanceof Tag))
			return false;
		return ((Tag)obj).getId().intValue()==getId().intValue();
	}
	
	
}